<include file="public@header" />
<style>
    .col-left {float:left;width:200px;margin-right:15px;height: 580px;}
    .col-right {zoom:1;overflow:hidden;}
    .smart-widget-header {
        background-color: #3a8eff;
        color: #fff;
        padding: 9px;
    }
    .active {
        background: #1890ff;
    }
    .active a{
        color: #fff;
    }
    .layui-card-body .layui-table{margin:0;}
</style>
</head>
<body>
    <div class="layui-tab-content js-check-wrap">
        <div class="layui-card">
            <div class="layui-card-body">
                <form class="js-ajax-form"  action="{:url('rbac/catPrivPost')}" method="post">
                    <php>
                        $count = count($sites);
                    </php>
                    <if condition="$count gt 1">
                        <div class="col-left">
                            <!-- <div class="sideBar">
                                <p class="list-group-item" style="color:#3a8eff;font-weight:bold;"><i class="fa fa-sitemap normal"></i> 站点选择</p>
                                <volist name="sites" id="vo">
                                    <a class="list-group-item <if condition="$vo['site_id'] == $site_id">active</if> " href="{:url('Rbac/catpriv',array('id'=>$role_id, 'site_id'=>$vo['site_id']))}">{$vo.name}</a>
                                </volist>
                            </div> -->
                            <table class="layui-table" lay-skin="line">
                                <thead>
                                    <tr><th><p class="list-group-item" style="font-weight:bold;"><i class="fa fa-sitemap normal"></i> 站点选择</p></th></tr>
                                </thead>
                                <volist name="sites" id="vo">
                                    <tr>
                                        <td class="<if condition="$vo['site_id'] == $site_id">active</if>"><a style="font-size:13px;display:block;" class="list-group-item  " href="{:url('Rbac/catpriv',array('id'=>$role_id, 'site_id'=>$vo['site_id']))}">{$vo.name}</a></td>
                                    </tr>
                                </volist>
                            </table>
                        </div>
                    </if>
                    <div class="col-right">
                        <div style="">
                            <if condition="$articlecat || $goodscat || $branchcat">
                                <!-- 文章分类 -->
                                <if condition="$articlecat">
                                    <div class="message-table">
                                        <div class='smart-widget-header'>文章分类操作权限</div>
                                        <table class="layui-table" lay-skin="line" id="authrule-tree1">
                                            <thead>
                                                <tr>
                                                    <th>栏目名称</th>
                                                    <th width="30" align="center">查看</th>
                                                    <th width="30" align="center">添加</th>
                                                    <th width="30" align="center">编辑</th>
                                                    <th width="30" align="center">删除</th>
                                                    <th width="30" align="center">导出</th>
                                                </tr>
                                            </thead>    
                                            <tbody>
                                                {$articlecat}
                                            </tbody>
                                        </table>
                                    </div>
                                </if>

                                <!-- 故障分类 -->
                                <if condition="$repairscat">
                                    <div class="message-table">
                                        <div class='smart-widget-header'>故障分类操作权限</div>
                                        <table class="layui-table" lay-skin="line" id="authrule-tree1">
                                            <thead>
                                                <tr>
                                                    <th>栏目名称</th>
                                                    <th width="30" align="center">查看</th>
                                                    <th width="30" align="center">添加</th>
                                                    <th width="30" align="center">编辑</th>
                                                    <th width="30" align="center">删除</th>
                                                    <th width="30" align="center">导出</th>
                                                </tr>
                                            </thead>    
                                            <tbody>
                                                {$repairscat}
                                            </tbody>
                                        </table>
                                    </div>
                                </if>
                                
                                <!-- 基地文章分类 -->
                                <if condition="$branchcat">
                                    <table class="layui-table" lay-skin="line" id="authrule-tree2">
                                        <thead>
                                            <tr><td colspan="6" style="color:#18BC9C;" >基地文章分类操作权限</td></tr>
                                            <tr>
                                                <th>栏目名称</th>
                                                <th width="30" align="center">查看</th>
                                                <th width="30" align="center">添加</th>
                                                <th width="30" align="center">编辑</th>
                                                <th width="30" align="center">删除</th>
                                                <th width="30" align="center">导出</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            {$branchcat}
                                        </tbody>
                                    </table>
                                </if>

                                <!-- 产品分类 -->
                                <if condition="$goodscat">
                                    <div class="message-table">
                                        <div class='smart-widget-header'>产品分类操作权限</div>
                                        <table class="layui-table" lay-skin="line" id="authrule-tree3">
                                            <thead>
                                                <tr>
                                                    <th>栏目名称</th>
                                                    <th width="30" align="center">查看</th>
                                                    <th width="30" align="center">添加</th>
                                                    <th width="30" align="center">编辑</th>
                                                    <th width="30" align="center">删除</th>
                                                    <th width="30" align="center">导出</th>
                                                </tr>
                                            </thead>
                                
                                            <tbody>
                                                {$goodscat}
                                            </tbody>
                                        </table>
                                    </div>
                                </if>
            
                                <div style="padding-top:10px;">
                                    <input type="hidden" name="role_id" value="{$role_id}" />
                                    <input type="hidden" name="site_id" value="{$site_id}" />
                                    <if condition="cmf_auth_check(cmf_get_current_admin_id(), 'admin/Rbac/authorizePost')">
                                        <button class="layui-btn layui-btn-normal js-ajax-submit" type="submit">{:lang('SAVE')}</button>
                                    </if>
                                </div>
                            <else>
                                <center>
                                    <p style="padding:15px;font-size:24px;">暂无数据</p>
                                </center>
                            </if>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <script src="__STATIC__/js/admin.js"></script>
    <script src="__STATIC__/js/jquery.slimscroll.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            Wind.css('treeTable');
            Wind.use('treeTable', function () {
                $("#authrule-tree1").treeTable({
                    indent: 20
                });
                $("#authrule-tree2").treeTable({
                    indent: 20
                });
                $("#authrule-tree3").treeTable({
                    indent: 20
                });
            });
            
            $(".col-right").slimScroll({
                height: "580px",
                size: "5px",
            });

            $(".sideBar").slimScroll({
                height: "580px",
                size: "0px"
            });
        });

        function checknode(obj) {
            var chk = $("input[type='checkbox']");
            var count = chk.length;

            var num = chk.index(obj);
            var level_top = level_bottom = chk.eq(num).attr('level');
            // for (var i = num; i >= 0; i--) {
            //     var le = chk.eq(i).attr('level');
            //     if (le <level_top) {
            //         chk.eq(i).prop("checked", true);
            //         var level_top = level_top - 1;
            //     }
            // }
            for (var j = num + 1; j < count; j++) {
                var le = chk.eq(j).attr('level');
                if (chk.eq(num).prop("checked")) {

                    if (le > level_bottom){
                        chk.eq(j).prop("checked", true);
                    }
                    else if (le == level_bottom){
                        break;
                    }
                } else {
                    if (le >level_bottom){
                        chk.eq(j).prop("checked", false);
                    }else if(le == level_bottom){
                        break;
                    }
                }
            }
        }
    </script>
</body>
</html>
